package day3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

//模拟Scanner对象获取控制台的数据 next() nextInt()
public class TestScanner {
    private  InputStream is;
    private BufferedReader br;
    public TestScanner(InputStream is){
        this.is = is;
        InputStreamReader isr = new InputStreamReader(is);
        br = new BufferedReader(isr);
    }
    public String next(){
        String msg = null;
        try {
             msg = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return msg;
    }
    public int nextInt(){
        String msg = null;
        try {
            msg = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        int result = Integer.parseInt(msg);
        return result;
    }
    public static void main(String[] args) throws IOException {
        //System.in 表示系统输入流 可以获取控制台数据 本质上是一个字节输入流
        //Scanner sc = new Scanner(System.in);
        TestScanner ts = new TestScanner(System.in);

        //sc.next() sc.nextInt()
        InputStream is = System.in;//字节输入流
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        while (true){
            System.out.println("请输入内容:");
            String msg = br.readLine();
            System.out.println("控制台读取数据："+msg);
        }
    }
}
class Test{
    public static void main(String[] args) {
        TestScanner ts = new TestScanner(System.in);
        System.out.println("请输入姓名:");
        String name = ts.next();
        System.out.println("请输入年龄:");
        int age = ts.nextInt();
        System.out.println(name+" "+age);
    }
}